package br.edu.ufcg.lsd.wbis.control.equipment;

import java.sql.Date;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

/**
 * This class represents a router
 * @author Paulo Ricardo
 *
 */
@Entity
public class Router extends Equipment {

	@Enumerated(EnumType.STRING)
	private RouterType routerType;
	
	private String vlan;
	
	private int ports;

	@SuppressWarnings("unused")
	private Router(){};
	
	/**
	 * 
	 * @param inventoryCode
	 * @param brand
	 * @param serialCode
	 * @param aquisitionDate
	 * @param model
	 * @param localization
	 * @param receipt
	 * @param reserve
	 * @param available
	 * @param routerType
	 * @param vlan
	 * @param ports
	 */
	public Router(String inventoryCode, String brand, String serialCode,
			Date aquisitionDate, String model, String localization,
			byte[] receipt, boolean available, RouterType routerType, String vlan, int ports) {
		super(inventoryCode, brand, serialCode, aquisitionDate, model, localization,
				receipt, false, available, Router.class);
		this.routerType = routerType;
		this.vlan = "";
		this.ports = ports;
		if(routerType.equals(RouterType.SWITCH_KVM))
			this.vlan = vlan;
	}

	/**
	 * 
	 * @return
	 */
	public String getVlan() {
		return vlan;
	}

	/**
	 * 
	 * @param vlan
	 */
	protected void setVlan(String vlan) {
		this.vlan = vlan;
	}

	/**
	 * 
	 * @param ports
	 */
	protected void setPorts(int ports) {
		this.ports = ports;
	}

	/**
	 * 
	 * @return
	 */
	public int getPorts() {
		return ports;
	}
	

	/**
	 * 
	 * @param routerType
	 */
	protected void setRouterType(RouterType routerType) {
		this.routerType = routerType;
	}

	/**
	 * 
	 * @return
	 */
	public RouterType getRouterType() {
		return routerType;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ports;
		result = prime * result + ((routerType == null) ? 0 : routerType.hashCode());
		result = prime * result + ((vlan == null) ? 0 : vlan.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Router other = (Router) obj;
		if (ports != other.ports)
			return false;
		if (routerType == null) {
			if (other.routerType != null)
				return false;
		} else if (!routerType.equals(other.routerType))
			return false;
		if (vlan == null) {
			if (other.vlan != null)
				return false;
		} else if (!vlan.equals(other.vlan))
			return false;
		return true;
	}

}
